//
//  CollectionView.m
//  AoJi
//
//  Created by IMacLife on 15/1/30.
//  Copyright (c) 2015年 xuanheng. All rights reserved.
//
//个人中心

#import "CollectionView.h"
#import "Color.h"

@implementation CollectionView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self loadView];
        [self loadData];
    }
    return self;
}

//加载view
-(void)loadView
{
    _tableview = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
    _tableview.delegate=self;
    _tableview.dataSource=self;
    _tableview.backgroundColor=[UIColor clearColor];
    [self addSubview:_tableview];
    
    imgArray = @[@"xuexiao",@"huodong",@"mianshi",@"luxian",@"kecherng"];
    array = @[@"学校详情",@"活动详情",@"面试详情",@"路线详情",@"课程详情"];
    
    UIView *footView = [[UIView alloc]init];
    footView.backgroundColor=[Color colorFromHexRGB:@"e4e4e4"];
    _tableview.tableFooterView=footView;
}

-(void)loadData
{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"lastid"]=@"0";
    
    [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:param WithApi:@"me/favorite?lastid=0" WhenSuccess:^(NSMutableDictionary *response) {
        NSLog(@"%@",response);
        
        dataArray = response;
    } WhenFailure:^(NSError *failure) {
        NSLog(@"%@",failure);
    }];
}

#pragma mark ----------------UITableViewDelegate
//一个分区显示多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return array.count;
}


//UITableViewCell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.imageView.image = [UIImage imageNamed:imgArray[indexPath.row]];
    cell.textLabel.text=array[indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    
    
    return cell;
}

//cell   -------   select
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:
        {
            NSLog(@"学校详情");
        }
            break;
        case 1:
        {
          
            NSLog(@"活动详情");
            
        }
            break;
        case 2:
        {
            NSLog(@"面试详情");
           
        }
            break;
            
        case 3:
        {
            NSLog(@"路线详情");
            
        }
            break;
            
            
        default:
        {
            
            NSLog(@"课程详情");
        }
            
            break;
    }
}

//cell行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 51;
}

@end
